<?php

class Core_Data_SQL_Structure_Field {

    public $Table;

    private $strName;
    private $boolRequired = false;
    private $mixDefaultValue = null;
    private $constDataType;
    private $constKeyType = null;
    private $boolAutoIncrement = false;
    private $intLength = null;

    function __construct ( $strName, $constDataType = Core_Data_SQL_DataTypes::TEXT ) {
        $this->strName = $strName;
        $this->constDataType = $constDataType;
    }

    function __toString () {
        return $this->strName;
    }

    public function rename ( $strName ) {
        $strQueryTextRequired = ( $this->isRequired() ) ? "NOT NULL" : "NULL";
        $strQuery = "ALTER TABLE `" . $this->Table . "` CHANGE `" . $this . "` `" . $strName . "` " . Core_Data_SQL_DataTypes::getQueryText( $this->getDataType, $this->Table->Database->Connection->ServerInformation->Type ) . " " . $strQueryTextRequired;
        $this->Database->Connection->query( $strQuery );
        $this->strName = $strName;
    }

    public function isRequired () {
        return $this->boolRequired;
    }

    public function setRequired () {
        $this->boolRequired = true;
    }

    public function getDefaultValue () {
        return $this->mixDefaultValue;
    }

    public function setDefaultValue ( $mixDefaultValue ) {
        $this->mixDefaultValue = $mixDefaultValue;
    }

    public function getDataType () {
        return $this->constDataType;
    }

    public function setDataType ( $constDataType ) {
        $this->constDataType = $constDataType;
    }

    public function isKey () {
        return ( $this->constKeyType ) ? true : false;
    }

    public function getKeyType () {
        return $this->constKeyType;
    }

    public function setKeyType ( $constKeyType ) {
        $this->constKeyType = $constKeyType;
    }
    
    public function autoIncrement ( $boolAutoIncrement = null ) {

        if ( $boolAutoIncrement === null ) {
            return $this->boolAutoIncrement;
        }

        $this->boolAutoIncrement = $boolAutoIncrement;

    }

    public function getLength () {
        return $this->intLength;
    }

    public function setLength ( $intLength ) {
        $this->intLength = $intLength;
    }

}

?>